/* Global definitions for DejaVu
   Some definitions required by many modules
 */

/*
    DejaVu, a Utility for the Psion Series 3
    Version 1.0a
    Copyright (C) 1993  J Cade Roux

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 * See the file COPYING for the GNU General Public License.
 * Mail: Cade Roux
 *			c/o Dubroca
 *			Box 513
 *			Boutte, LA  70039
 *			USA
 */

#ifndef GLOBAL_H
	#define GLOBAL_H

#ifndef PLIB_H
	#include <plib.h>
#endif

#ifndef WLIB_H
	#include <wlib.h>
#endif

#ifndef HWIF_H
	#include <hwif.h>
#endif

#ifndef BOOL
	#define BOOL	INT
#endif

#ifndef TRUE
	#define TRUE	1
#endif

#ifndef FALSE
	#define FALSE	0
#endif

#ifndef MIN
	#define MIN(a,b)	((a) < (b) ? (a) : (b))
#endif

#ifndef MAX
	#define MAX(a,b)	((a) > (b) ? (a) : (b))
#endif

#include <utils.h>				/* Utility Routines */

typedef struct FILE_DATA_TAG {
	VOID *		pfcb ;						/* pointer to file control block */
	TEXT			name[P_FNAMESIZE] ;		/* ZTS name of file */
	ULONG			size ;						/* size of file in bytes */
} FILE_DATA ;

/* General File Operations - some of which can be supported by particular
   modules.
 */

enum {	FO_NONE = 0,
			FO_UP,
			FO_DOWN,
			FO_PAGE_UP,
			FO_PAGE_DOWN,
			FO_TOP,
			FO_BOTTOM,
			FO_GOTO,
			FO_FIND,
			FO_AGAIN } ;

/** General routines in global.c **/

GLREF_C VOID Quit(VOID) ;					/* Quit program */
GLREF_C VOID MainDialog(VOID) ;			/* Return to main dialog */

/** Main window rountines **/

GLREF_C INT GetMainWid(VOID) ;
GLREF_C BOOL MoveMainWindow(INT key_dir) ;	/* Where key_dir is a directional keypress */

GLREF_C VOID SetMainWindowExtent(	WORD tl_x,
												WORD tl_y,
												WORD width,
												WORD height) ;

GLREF_C VOID GetMainWindowExtent(P_EXTENT *pextent) ;
GLREF_C VOID PrintString(TEXT *str, INT line) ;
GLREF_C VOID CopytoMainWindow(UINT bitmap_id, P_RECT *prect) ;

GLREF_C VOID UpdateStatus(TEXT *str) ;
GLREF_C VOID UpdateXScroll(SCROLL_BAR_STATE *pbarstate) ;
GLREF_C VOID UpdateYScroll(SCROLL_BAR_STATE *pbarstate) ;

#define VU_ENV "vuname"

typedef struct GLOB_TAG {
	BOOL			main ;				/* Return to main dialog */
	BOOL			quit ;				/* Quit program entirely */
} GLOB ;

typedef struct GFX_TAG {
	UINT			win_id ;				/* Main window id */
	W_WINDATA	wdata ;				/* Main window data */
	BOOL			super ;				/* Main window a super-bitmap? */
	UINT			style ;				/* Main window text style */

	BAR_OBJ		status_bar ;		/* status bar */
	BAR_OBJ		scroll_x ;			/* Horizontal scroll bar */
	BAR_OBJ		scroll_y ;			/* Vertical scroll bar */
} GFX ;

#define TEXT_LEADING		1

typedef struct METRICS_TAG {
	UINT			text_ascent ;
	UINT			text_height ;
	P_POINT		scr_size ;
	P_POINT		disp_size ;
} METRICS ;

/* Global data
 */

GLREF_D WSERV_SPEC *		wserv_channel ;
GLREF_D TEXT *				DatCommandPtr ;

GLREF_D FILE_DATA			file ;
GLREF_D GLOB				glob ;
GLREF_D GFX					gfx ;
GLREF_D METRICS			metrics ;

/* Application errors - all errors in p_leave etc. should be taken from here
 */
enum {	E_APP_MEM = E_APP_START,
			E_APP_NO_MENU
			} ;

/* Structure defining all call back fns
 */

#define STATUS_BAR			0x01
#define SCROLL_X				0x02
#define SCROLL_Y				0x04
#define SUPER					0x08

typedef struct DEFNS_TAG {
	INT					(*pfRecognize)(BYTE *, UINT) ;		/* Recognition function */

	TEXT **				pcmds ;										/* Menu commands */
	H_MENU_DATA *		pmdata ;										/* Menu data */
	INT					nHelp ;										/* Help index */
	UBYTE					flags ;										/* Flags for accessory windows */
	UBYTE					style ;										/* Main window text style */

#pragma save, ENTER_CALL

	INT					(*pfCleanUp)(VOID) ;						/* Type-specific clean up */
	INT					(*pfInit)(VOID) ;							/* Init */
	INT					(*pfUpdate)(VOID) ;						/* Update display */
	INT					(*pfFileInfo)(VOID) ;					/* Info about file */
	INT					(*pfMenuExec)(INT) ;						/* Menu commands */
	INT					(*pfPlainKey)(WMSG_KEY *) ;			/* Plain key commands */

#pragma restore

} DEFNS ;

typedef VOID (*DEFN_FN)(DEFNS *) ;

#endif
